####
#
# Copyright 2007 B. Chandler Carruth
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
####
#
# ./lib/rcons/tool_target.rb
#
# This file provides very *very* simple abstraction point for any tools.
#
####

require( 'rcons/target' )

module RCons

  # The +ToolTarget+ class proides an extrememly simple abstraction for
  # any tools, such as compilers, that may be used in a build process.  This
  # class should be extended and implemented for each tool needed by a
  # build.
  #
  # An example of a child class:  +CompilerTarget+
  #
  # Extends +Target+.
  class ToolTarget < Target

    # initialize a simple command target
    # Initializes the +ToolTarget+ object by first using the constructor
    # from +Target+ and then providing tool-specific initialization code.
    #
    # Inputs:
    #
    # +build_env+:: an +Environment+.
    # +name+:: the name of the target.
    # +opts+:: a list of options.
    def initialize( build_env, name, opts = Hash.new() )
      # handle all the defaults for a target
      super( build_env, File.join( 'tool', name ), opts )

      @min_version = []
      if opts[ :min_version ]
        if opts[ :min_version ].kind_of? Array
          @min_version = opts[ :min_version ]
        else
          @min_version = [ opts[ :min_version ] ]
        end
      end

      @max_version = []
      if opts[ :max_version ]
        if opts[ :max_version ].kind_of? Array
          @max_version = opts[ :max_version ]
        else
          @max_version = [ opts[ :max_version ] ]
        end
      end
    end

    # The ToolTarget overriden Builder class.
    class Builder < superclass()::Builder
      # This is the custom method for building this type of target
      def do_build( has_changed )
        super( has_changed )
      end
    end
  end
end

